/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller.ShowServlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Controller.CoreServlet.Ultility.*;
import javax.servlet.http.HttpSession;
import java.util.*;
import java.text.*;
import Model.ObjectBean.ViewBean.*;
import javax.servlet.RequestDispatcher;
/**
 *
 * @author chickencake1
 */
public class ShowCartServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      
        
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        RequestDispatcher dispatcher=request.getRequestDispatcher("/WEB-INF/MainJSP/CartPage.jsp");
        dispatcher.forward(request, response);
        
        ShoppingCart cart=(ShoppingCart) request.getSession().getAttribute("shoppingcart");
        if(cart==null)
            out.println("Giỏ hàng của bạn trống");
        else
        {
            List ItemsOrdered = cart.getItemsOrdered();
            if(ItemsOrdered.size()==0)
                out.println("Giỏ hàng của bạn rỗng");
            else
                for(int i=0;i<ItemsOrdered.size();i++)
                {
                    ItemOrder order = (ItemOrder)ItemsOrdered.get(i);
                    out.println("ID="+order.getItem_ID()+"\n");
                    out.println("Hình ảnh="+order.getCoverImage()+"\n");
                    out.println("Tựa sách="+order.getLabel()+"\n");
                    out.println("Số sách="+order.getNumberItems()+"\n");
                    out.println("Giá đơn vi="+order.getUnitCost()+"\n");
                    out.println("tổng tiền="+order.getTotalCost()+"\n");
                    
          
                }
        }
        
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
